class ScroePanel {
  // 分数
  score: number = 0;
  scoreElement: HTMLElement;
  // 等级
  level: number = 1;
  levelElement: HTMLElement;

  // 最高等级
  maxLevel: number;
  // 设置步进数，代表多少分为一个等级
  scoreUp: number;

  constructor(maxLevel: number = 10, scoreUp: number = 10) {
    this.scoreElement = document.getElementById('score') as HTMLElement;
    this.levelElement = document.getElementById('level') as HTMLElement;
    this.maxLevel = maxLevel;
    this.scoreUp = scoreUp;
  }

  // 加分方法
  add() {
    // 使分数自增
    this.scoreElement.innerHTML = ++this.score + '';
    // 判断分数是多少从而提升等级
    if (this.score % this.scoreUp === 0) {
      this.levelUp()
    }
  }

  // 等级提升
  levelUp() {
    if (this.level < this.maxLevel) {
      this.levelElement.innerHTML = ++this.level + ''
    }
  }

}

export default ScroePanel;